﻿using System;
using UniversalEditor.Base.Mvvm;

namespace UniversalEditor.Base.MenuBarItems
{
	public class MenuCheckCommand : MenuItemBase
	{
		private readonly string _name;
		private readonly SimpleCommand<bool> _command;

		private bool _checked;

		public MenuCheckCommand(string name, SimpleCommand<bool> command)
		{
			if (string.IsNullOrEmpty(name)) 
				throw new ArgumentNullException("name");
			if (command == null)
				throw new ArgumentNullException("command");

			_name = name;
			_command = command;
		}

		public override string Name
		{
			get { return _name; }
		}

		public override string Icon
		{
			get { return null; }
		}

		public bool Checked
		{
			get { return _checked; }
			set
			{
				if (_checked == value)
					return;

				_checked = value;
				RaisePropertyChanged("Checked");
				_command.Execute(_checked);
			}
		}

		public override string ToString()
		{
			return string.Format("{0}, Checked: {1}", _name, _checked);
		}
	}
}
